package com.sophie.util;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 给前端统一返回的结果，针对业务层的所有方法实现都返回该对象
 */
@Data
@Accessors(chain = true)  //开启链式编程
public class ResultVO {
    /**
     * 状态码，为0表示成功状态
     */
    private Integer code;
    //状态
    private String status;
    //返回文字描述
    private String msg;
    //传递给前端的数据
    private Object data;

    /**
     * 封装统一成功返回结果
     *
     * @return
     */
    public static ResultVO ok() {
        ResultVO r = new ResultVO();
        r.code = 0;
        r.status="success";
        r.msg = "操作成功";
        return r;
    }

    public static ResultVO ok(String msg) {
        ResultVO r = new ResultVO();
        r.code = 0;
        r.status="success";
        r.msg = msg;
        return r;
    }

    /**
     * 封装统一失败返回结果
     *
     * @return
     */
    public static ResultVO fail() {
        ResultVO r = new ResultVO();
        r.code = -1;
        r.status="fail";
        r.msg = "操作失败";
        return r;
    }

    public static ResultVO fail(String msg) {
        ResultVO r = new ResultVO();
        r.code = -1;
        r.status="fail";
        r.msg = msg;
        return r;
    }
}
